package org.ricks.condition1;

import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.function.BiConsumer;

public class ConditionBindingService {
    // 条件到业务的映射存储
    private final Map<Condition, List<BiConsumer<String, Condition>>> bindings = new ConcurrentHashMap<>();

    // 注册条件触发逻辑
    public void bindCondition(Condition condition, BiConsumer<String, Condition> handler) {
        bindings.computeIfAbsent(condition, k -> new CopyOnWriteArrayList<>()).add(handler);
    }

    // 触发条件关联业务
    public void triggerConditionEffects(String playerId, Condition condition) {
        List<BiConsumer<String, Condition>> handlers = bindings.get(condition);
        if (handlers != null) {
            handlers.forEach(handler -> handler.accept(playerId, condition));
        }
    }
}
